//
//  BGfileupload.m
//  bigMall
//
//  Created by ios on 16/9/13.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGfileupload.h"
#import "AFNetworking.h"
#import "BGFileUpLoadModel.h"
#import "MJExtension.h"

@implementation BGfileupload
+ (void)getFileUpLoadPath:(NSString *)path andParamters:(NSDictionary *)paramters andData:(NSData *)fdata success:(void (^)(NSObject *))success failure:(void (^)(NSError *))failure {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //设置content-type
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    //参数列表（字典类型啊）

    //用post上传图片
    /*
     第一个参数：接口的网址路径
     第二个参数：参数列表（字典类型啊）
     第三个参数：上传图片的block（请求体）
     第四个参数：进度block
     第五个参数：成功block
     第六个参数：失败block
     */
    [manager POST:path parameters:paramters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        [formData appendPartWithFileData:fdata name:@"icon"fileName:@"upload.png"mimeType:@"image/png"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        BGFileUpLoadModel *result = [BGFileUpLoadModel objectWithKeyValues:responseObject];
        
        if (success) {
            success(result);
        }
        
        //        [self showMessage:dic[@"msg"]];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (failure) {
            failure(error);
        }
        
    }];
    
}
@end
